package com.climber.spb_rabbitmq.exchange.topic;


import com.climber.spb_rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;


public class TopicPublisher {
    private static String EXCHANGE_NAME="topic_logs";
    public static void main(String[] args) {
        Channel channel = RabbitMQUtils.getChannel();

            try{
//            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
            Map<String, String> bindingKeyMap = new HashMap<>();
            bindingKeyMap.put("q1.q2.rabbit","q2.q1.rabbit");
            bindingKeyMap.put("aa.q2.elephant","aa.q1.elephant");
            bindingKeyMap.put("q1.orange.fox","q2.orange.fox");
            bindingKeyMap.put("lazy.brown.q3","lazy.brown.q3");
            bindingKeyMap.put("q1.q2.q3","q1.q2.q3");

            for (Map.Entry<String, String> bindingKeyEntry:bindingKeyMap.entrySet()){
                String bindingKey =bindingKeyEntry.getKey();
                String message = bindingKeyEntry.getValue();
                channel.basicPublish(EXCHANGE_NAME,bindingKey, null,message.getBytes("UTF-8"));
                System.out.println("生产者发出消息" + message);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
